package com.dandan.mobilelover.service.impl;

import java.util.Date;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dandan.mobilelover.common.StringUtil;
import com.dandan.mobilelover.dao.UserRepository;
import com.dandan.mobilelover.entity.User;
import com.dandan.mobilelover.service.UserService;


@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Inject
	private UserRepository userRepository;
	
	@Override
	public void saveUser(User user) {
		System.out.println("***************save user start******************");
		User uu  = userRepository.findOne(1);
		System.out.println("***************save user end "+ uu.getNickname()+"******************");
	}

	@Override
	public User checkLogin(String passport, String password) {
		User user = null;
		if(passport != null && password != null){
			if(password.length()<32) {//判断密码是否已经是MD5加密
				password = StringUtil.getMD5Str(password);
			}
			user = userRepository.findByPassportAndPassword(passport, password);
		}
		if(user!=null) {
			Date date = new Date();
//			if(user.getActivatedAt()==null) {
				user.setActivatedAt(date);
//			}
			userRepository.save(user);
		}
		return user;
	}

 

}
